package com.example.spi;

import org.springframework.core.io.support.SpringFactoriesLoader;

import java.util.List;

/**
 * @Date 2022/10/7
 * @Author Jonathan
 * @link {https://www.51cto.com/article/712535.html}
 */
public class SpringSpiTest2 {
    public static void main(String[] args) {
        // 调用SpringFactoriesLoader.loadFactories方法加载DataBaseSPI接口所有实现类的实例
        List<DataBaseSPI> spis = SpringFactoriesLoader.loadFactories(DataBaseSPI.class, Thread.currentThread().getContextClassLoader());

        // 遍历DataBaseSPI接口实现类实例
        for (DataBaseSPI spi : spis) {
            spi.dataBaseOperation();
        }
    }
}
